package es.armaplus.struts.actions.clientes;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import es.armaplus.business.BusinessFactory;
import es.armaplus.business.ClienteBusiness;
import es.armaplus.commons.Constantes;
import es.armaplus.ddbb.base.Clientes;
import es.armaplus.struts.actions.BaseAction;
import es.armaplus.struts.forms.clientes.ClientesForm;

/**
 * Acci�n Post-carga al formulario de alta del cliente.
 * 
 * @author Texaco
 *
 */
public class BuscadorDo extends BaseAction {

	
	private static final Log log = LogFactory.getLog(BuscadorDo.class);
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		log.debug(Constantes.METHOD_BEGIN);
		
		ClientesForm cForm = (ClientesForm) form;
		
		log.debug("Nombre del cliente a filtrar: " + cForm.getCliente().getNombre());
		ClienteBusiness cBusiness = BusinessFactory.getBusiness(ClienteBusiness.class);
		List <Clientes> listaClientesFiltrada = cBusiness.Buscar(
				cForm.getCliente());
		
		request.setAttribute(Constantes.ATTRIBUTE_CLIENTES, 
				listaClientesFiltrada);
		
		log.debug("tamaño de la lista filtrada: " + listaClientesFiltrada.size());
		log.debug(Constantes.METHOD_END);
		return mapping.findForward(Constantes.FORWARD_SUCCESS);
	}
}
